﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using dahtd4ever.GameScreens;

namespace dahtd4ever.GameScreens
{

    public class Pause
    {
        Game1 game;

        List<Text> menuItems;
        Text activeItem;
        int selection;

        SoundEffect select;
        SoundEffect enter;

        String menuTxt = "- Spiel pausiert - ";
        Vector2 titlePos = new Vector2(100, 50);

        public Pause(Game1 game)
        {
            this.game = game;

            #region Menu Items
            menuItems = new List<Text>();
            menuItems.Add(new Text(game, "Spiel fortsetzen", new Vector2(255, 160), true));
            menuItems.Add(new Text(game, "Einstellungen", new Vector2(255, 200), true));
            menuItems.Add(new Text(game, "Hauptmenu", new Vector2(255, 240), true));
            //menuItems.Add(new Text(game, "Beenden", new Vector2(255, 280), true));
            #endregion
            selection = 0;

            select = game.Content.Load<SoundEffect>("Sound\\Select");
            enter = game.Content.Load<SoundEffect>("Sound\\keyboard-click");
        }

        public void Update(GameTime gTime)
        {
            if (ScreenManager.lastState == GameState.Play)
            {
                selection = 0;
                ScreenManager.lastState = GameState.Pause;
            }

            if (ScreenManager.keyboard.MenuUp)
            {
                select.Play();

                if (selection == 0)
                    selection = 2;
                else
                    selection--;
            }
            else if (ScreenManager.keyboard.MenuDown)
            {
                select.Play();

                if (selection == 2)
                    selection = 0;
                else
                    selection++;
            }

            else if (ScreenManager.keyboard.MenuSelect)
            {
                enter.Play();

                switch (selection)
                {
                    case 0: ScreenManager.gameState = GameState.Play;
                        break;
                    case 2: ScreenManager.gameState = GameState.Menu;
                        break;
                }
            }

            activeItem = menuItems[selection];

            foreach (Text t in menuItems)
            {
                if (t == activeItem)
                    t.setBubble(true);
                else
                    t.setBubble(false);
                t.update(gTime);
            }
        }


        public void Draw()
        {
            game.spriteBatch.Begin();
            titlePos.X = (game.GraphicsDevice.Viewport.Width / 2 - game.font1.MeasureString(menuTxt).X / 2);
            game.spriteBatch.DrawString(game.font1, menuTxt, titlePos, Color.White);
            game.spriteBatch.End();

            foreach (Text t in menuItems)
                t.draw();
        }
    }
}
